<?php

class Core_Table_Customer_Product extends Kd_Data_Table {

	private $_relationTable = '{t}customer_category_product';

	public function __construct() {
		parent::__construct();
	}

	public function insertRelation($productId, array $categoryIds, $transaction = NULL){
		$insert = Kd_Data_Factory::getInsertDcl()
			->into($this->_relationTable)
			->value('product_id', $productId)
			->value('category_id', ':categoryId:i')
			->toSql();
		$driver = $this->getDbDriver($transaction);
		foreach($categoryIds as $categoryId){
			$driver->setSql($insert, array('categoryId'=>$categoryId))->execute();
		}
	}

	public function deleteRelation($productId, $transaction = NULL){
		Kd_Data_Factory::getDeleteDcl()
		->from($this->_relationTable)
		->where()->eq('product_id', $productId)->closest()
		->setDbDriver($this->getDbDriver($transaction))
		->execute();
	}
}